package com.zhu.controller;

import com.zhu.pojo.Order;
import com.zhu.pojo.Person;
import com.zhu.pojo.Result;
import com.zhu.service.OrderService;
import jakarta.persistence.criteria.CriteriaBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/getOrderStatistics")
    public Result getOrderStatistics(){
        try {
            Map<String,Object> list = orderService.getOrderStatistics();
            return Result.ok(list);
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("发生错误");
        }
    }

    @PostMapping("/unassigned")
    public List<Order> unassigned(){
        return orderService.unassigned();
    }

    @PostMapping("/perlist")
    public List<Person> perlist(){
        return orderService.perlist();
    }

    @PostMapping("/paidan")
    public void paidan(@RequestBody Map<String,Integer> map){

        orderService.paidan((int) map.get("business_id"),(int)map.get("personnel_id"));
    }

    @PostMapping("/assigned")
    public List<Order> assigned(){
        return orderService.assigned();
    }

    @PostMapping("/shoudan")
    public void shoudan(@RequestBody Integer id){
        orderService.shoudan(id);
    }
}
